//
//  ByViewPhysicalCheckAppointment.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/12/11.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewPhysicalCheckAppointment.h"

// cell
#import "ByCellAppointmentListItem.h"

@interface ByViewPhysicalCheckAppointment() <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *table;

@end


@implementation ByViewPhysicalCheckAppointment
{
    NSDateComponents *_currentCom;
}
- (void)setFrame:(CGRect)frame {
    
    [super setFrame:frame];
    
    [self createViews];
}
- (void)createViews {
    if (self.table){
        return;
    }
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDate *date = [NSDate date];
    _currentCom = [cal components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond | NSCalendarUnitWeekday fromDate:date];
    
    NSArray *weekDays = @[@"周日", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六"];
    UILabel *todaylabel = [[UILabel alloc] init];
    todaylabel.text = [NSString stringWithFormat:@"%li.%li.%li(%@)", _currentCom.year, _currentCom.month, _currentCom.day, weekDays[_currentCom.weekday - 1]];
    todaylabel.font = FONT(14);
    todaylabel.textAlignment = NSTextAlignmentCenter;
    todaylabel.textColor = [UIColor blackColor];
    [self addSubview:todaylabel];
    [todaylabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(@0);
        make.height.equalTo(@40);
    }];
    
    self.table = [[UITableView alloc] init];
    self.table.backgroundColor = BY_TABLE_COLOR;
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.table.delegate = self;
    self.table.dataSource = self;
    [self addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(40, 0, 0, 0));
    }];
    
    [self.table registerClass:[ByCellAppointmentListItem class] forCellReuseIdentifier:@"cell"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 20;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ByCellAppointmentListItem *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.testTag = indexPath.row;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor = [UIColor whiteColor];
    label.font = FONT(16);
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = rgba(149, 214, 250, 1);
    
    if (section == 0) {
        label.text = @"2017.12";
    } else {
        label.text = @"2018.1";
    }
    return label;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 3;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [UIView new];
//    view.backgroundColor = BY_LINE_COLOR;
    return view;
}

@end
